package com.game.server.message.proto.execute;

import java.util.Random;

import com.comm.ISession;
import com.game.majiang.config.DataManager;
import com.game.majiang.config.LogManager;
import com.game.majiang.vo.CheckCodeVo;
import com.game.server.message.proto.in.AbstractVerificationCodeReq;
import com.game.server.message.proto.out.VerificationCodeRsp;
import com.game.server.sms.SendSMS;
import com.game.server.util.Util;
import lombok.extern.log4j.Log4j;

public class VerificationCodeReq extends AbstractVerificationCodeReq {

    @Override
    public void Execute(ISession session) {
		log.info("验证码");
        	VerificationCodeRsp rsp = new VerificationCodeRsp();
        	     Random r = new Random(System.currentTimeMillis());
        	    if (!Util.checkPhone(this.phone))
        	     {
        	       rsp.setIsOK((byte)1); 
        	     }
        	    else
        	     {
        	       int checkcode = r.nextInt(900000) + 100000;
        	       boolean sign = true;
        	       checkcode = 666666;
    	         //  boolean sign = SendSMS.getInstance().sendSMS(this.phone, String.valueOf(checkcode));
        	     //  LogManager.getInstance().Log("-------------sign:"+sign);
        	      if (sign)
        	       {
        	         CheckCodeVo.addCheckCode(0, this.phone, checkcode);

					 				 rsp.setIsOK((byte) 0);
        	       }
        	       else
        	       {
        	        rsp.setIsOK((byte)2); 
        	       }
        	    }

        	    session.send(rsp.Serialize());
        	  
        }
    }


